import errorFun from '../../util/errorFun';
import requestTimeOut from '../../util/requestTimeout';

Page({
    data: {
        bannerList: [
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner1.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner2.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner3.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner4.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner5.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner6.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner7.jpg" },
            { img: "cloud://j-1g278wytc94978ae.6a2d-j-1g278wytc94978ae-1304416950/banner/banner8.jpg" },
        ],
        dvdList: [],
    },
    onLoad(options) {
        this.getAllMusicData();
    },
    getAllMusicData () {
        wx.showLoading({
            title: '加载中',
            mask: true,
        })
        let timer = setTimeout(() => {
            requestTimeOut();
        },10000)
        wx.cloud.callFunction({
            name: 'getAllData',
            success: res => {
                wx.hideLoading();
                clearTimeout(timer);
                let dvdList = res.result.data;
                if (dvdList.length > 0) {
                    this.setData({
                        dvdList: dvdList
                    })
                } else {
                    wx.showToast({
                        title: '没有获取到数据',
                        duration: 2000,
                        mask: true
                    })
                }
            },
            fail:err => {
                errorFun(err);
            }
        })
    },
    handleBannerDvd (evt) {
        console.log("bannerEvt", evt.currentTarget.dataset.index);
    },
    bindDvdDetail (evt) {
        if (evt.target.dataset.ids && evt.target.dataset.ids != undefined) {
            wx.navigateTo({
                url: `../list/list?resid=${evt.target.dataset.ids}`,
            })
        }else{
            // 不需要处理
        }
    }
})